package com.threeigtache.threeigproject;

import android.app.Application;
import android.content.Context;
import android.os.Handler;
import android.os.Looper;
import android.os.Process;

import com.mob.MobSDK;
import com.threeigtache.been.IconSaveFile;
import com.zhy.http.okhttp.OkHttpUtils;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.PrintStream;
import java.util.concurrent.TimeUnit;

import okhttp3.OkHttpClient;

/**
 * Created by 赵航 on 2018/3/8 0008.
 */

public class CompontApplayCation extends Application {
    public static Context      context;
    public static Handler      mainHandler;
    public static String       appKey;
    public static IconSaveFile driverInfo;
    public static String       phone;
    public static String       postion;
    public static String       registCode;
    @Override
    public void onCreate() {
        super.onCreate();

        context = this;
        mainHandler = new Handler(Looper.getMainLooper());

        //网络请求框架
        OkHttpClient okHttpClient = new OkHttpClient.Builder()
                //                .addInterceptor(new LoggerInterceptor("TAG"))
                .connectTimeout(10000L, TimeUnit.MILLISECONDS)
                .readTimeout(10000L, TimeUnit.MILLISECONDS)
                //其他配置
                .build();

        OkHttpUtils.initClient(okHttpClient);


        //获取全局未捕获的异常
        //  Thread.setDefaultUncaughtExceptionHandler(new MyUncaghtHandler());



        //配置shareSdk
        MobSDK.init(context);
        driverInfo = new IconSaveFile();



    }


    public class MyUncaghtHandler implements Thread.UncaughtExceptionHandler {

        @Override
        public void uncaughtException(Thread thread, Throwable throwable) {
            //1.出现了错误保证不能出现xxx报错信息，直接闪退
            Process.killProcess(Process.myPid());
            //2.出现错误时将信息保存在sdk

            try {
                File errFile = new File(getExternalCacheDir().getAbsolutePath(), "err.text");
                PrintStream err = new PrintStream(errFile);
                throwable.printStackTrace(err);
            } catch (FileNotFoundException e) {
                e.printStackTrace();
            }

            //3,第二次打开应用时，直接将错误文件上传到服务器


        }
    }
}
